home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / c / dicepj20.lha / diceproject / sources / messages.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-03  |  3.4 KB  |  182 lines

  1.  
  2. #include <intuition/gadgetclass.h>
  3. #include <libraries/gadtools.h>
  4. #include <dos/dos.h>
  5.  
  6. #include <clib/intuition_protos.h>
  7. #include <clib/gadtools_protos.h>
  8. #include <clib/exec_protos.h>
  9. #include <clib/alib_protos.h>
  10. #include <clib/dos_protos.h>
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. #include "project.h"
  17.  
  18. BOOL KeepMessages;
  19.  
  20. struct List *MessList=NULL;
  21. struct MessNode *TopMess;
  22. long TopM;
  23.  
  24. struct MessNode {
  25.     struct Node node;
  26.     char *mess;
  27. };
  28.  
  29. void FreeMess( void ) {
  30.   struct MessNode *mn,*on;
  31.  
  32.     if ( MessList ) {
  33.     mn = MessList->lh_Head;
  34.     while( on = mn->node.ln_Succ ) {
  35.         free( mn->mess );
  36.         Remove( (struct Node *)mn );
  37.         free( mn );
  38.         mn = on;
  39.     }
  40.     free( MessList );
  41.     MessList = NULL;
  42.     }
  43. }
  44.  
  45. void NewMess( void ) {
  46.     MessList = malloc( sizeof(struct List) );
  47.     NewList( MessList );
  48. }
  49.  
  50. void AddMess( char *mess ) {
  51.   struct MessNode *mn = malloc( sizeof(struct MessNode) );
  52.  
  53.     mn->mess = strdup( mess );
  54.     mn->node.ln_Name = mn->mess;
  55.     AddTail( MessList , (struct Node *)mn );
  56. }
  57.  
  58. void DettachMess( void ) {
  59.     GT_SetGadgetAttrs( MessGadgets[0] , MessWnd , NULL , GTLV_Labels , 0 , TAG_DONE );
  60. }
  61.  
  62. void AttachMess( void ) {
  63.     GT_SetGadgetAttrs( MessGadgets[0] , MessWnd , NULL , GTLV_Labels , (long)MessList , TAG_DONE );
  64. }
  65.  
  66. BOOL CheckError( char *file ) {
  67.   struct FileInfoBlock fib;
  68.   char temp[200];
  69.   FILE *in;
  70.  
  71.     KeepMessages = TRUE;
  72.     if ( ( GetInfo( &fib , file )) && fib.fib_Size ) {
  73.     if ( !MessWnd ) {
  74.         OpenMessWindow( );
  75.         AddWinC( MessWnd , HandleMessIDCMP );
  76.     }
  77.     WindowToFront( MessWnd );
  78.     if ( CompileWnd )
  79.         WindowToFront( CompileWnd );
  80.     DettachMess( );
  81.     if ( !MessList )
  82.         NewMess( );
  83.     in = fopen( file , "r" );
  84.     fgets( temp , 200 , in );
  85.     while( !feof( in ) ) {
  86.         if ( strstr( temp , "Error" ) || strstr( temp , "Fatal" ) )
  87.         KeepMessages = FALSE;
  88.         temp[ strlen(temp)-1 ] = 0;
  89.         AddMess( temp );
  90.         fgets( temp , 200 , in );
  91.     }
  92.     fclose( in );
  93.     AttachMess( );
  94.     return( TRUE );
  95.     }
  96.     return( FALSE );
  97. }
  98.  
  99. BOOL ViewErrors( char *file ) {
  100.   char *file2;
  101.  
  102.     TopM = 0;
  103.     if ( !KeepMessages ) {
  104.     if ( MessWnd )
  105.         DettachMess( );
  106.     FreeMess( );
  107.     NewMess( );
  108.     if ( MessWnd )
  109.         AttachMess( );
  110.     KeepMessages = TRUE;
  111.     }
  112.     if ( !CheckError( file ) ) {
  113.     file2 = strdup( file );
  114.     file2[ strlen(file2)-1 ] = 0;
  115.     CheckError( file2 );
  116.     free( file2 );
  117.     }
  118.     if ( KeepMessages )
  119.     return( FALSE );
  120.     return( TRUE );
  121. }
  122.  
  123. int MessListClicked( void )
  124. {
  125. }
  126.  
  127. void UpDateTopMessage( void ) {
  128.     GT_SetGadgetAttrs( MessGadgets[0] , MessWnd , NULL , GTLV_Top , TopM , TAG_DONE );
  129. }
  130.  
  131. int MessCloseWindow( void )
  132. {
  133.     if ( MessWnd ) {
  134.     DettachMess( );
  135.     FreeMess( );
  136.     RemWinC( MessWnd );
  137.     CloseMessWindow( );
  138.     }
  139. }
  140.  
  141. int MessNewSize( void )
  142. {
  143.     DettachMess( );
  144.     RemWinC( MessWnd );
  145.     CloseMessWindow( );
  146.     OpenMessWindow( );
  147.     AddWinC( MessWnd , HandleMessIDCMP );
  148.     AttachMess( );
  149.     UpDateTopMessage( );
  150. }
  151.  
  152. void PrevMessage( void ) {
  153.     if ( !TopMess ) {
  154.     TopMess = MessList->lh_Head;
  155.     TopM = 0;
  156.     while( TopMess->node.ln_Succ->ln_Succ ) {
  157.         TopMess = TopMess->node.ln_Succ;
  158.         TopM ++;
  159.     }
  160.     } else {
  161.     if ( TopMess->node.ln_Pred->ln_Pred ) {
  162.         TopMess = TopMess->node.ln_Pred;
  163.         TopM --;
  164.     }
  165.     }
  166.     UpDateTopMessage( );
  167. }
  168.  
  169. void NextMessage( void ) {
  170.     if ( !TopMess ) {
  171.     TopMess = MessList->lh_Head;
  172.     TopM = 0;
  173.     } else {
  174.     if ( TopMess->node.ln_Succ->ln_Succ ) {
  175.         TopMess = TopMess->node.ln_Succ;
  176.         TopM ++;
  177.     }
  178.     }
  179.     UpDateTopMessage( );
  180. }
  181.  
  182.